#include "widget.h"
#include "ui_widget.h"
#include "syszuxpinyin.h"
#include <QDebug>
#include <QLineEdit>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    flag = 0;
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);//去掉标题栏

    subfom = new SubForm();

    m_edit = new My_lineEdit(this);
    m_edit->setObjectName("1");
    m_edit->setGeometry(10,10,200,20);

    m_edit2 = new My_lineEdit(this);
    m_edit2->setObjectName("2");
    m_edit2->setGeometry(10,50,200,20);

    syszuxpinyin = new SyszuxPinyin();

    connect(m_edit,SIGNAL(send_show(QString)),this,SLOT(show_syszupinyin_ui(QString)));
    connect(m_edit2,SIGNAL(send_show(QString)),this,SLOT(show_syszupinyin_ui(QString)));
    connect(subfom->m_edit,SIGNAL(send_show(QString)),this,SLOT(show_syszupinyin_ui(QString)));
    connect(subfom->m_edit2,SIGNAL(send_show(QString)),this,SLOT(show_syszupinyin_ui(QString)));

    connect(syszuxpinyin,SIGNAL(sendPinyin(QString)),this,SLOT(confirmString(QString)));
}

Widget::~Widget()
{
    delete ui;
}

void Widget::show_syszupinyin_ui(QString data){
    //qDebug()<< data;
    if(sender() == (QObject *)m_edit)
        flag = 1;
    if(sender() == (QObject *)m_edit2)
        flag = 2;
    if(sender() == (QObject *)subfom->m_edit)
        flag = 3;
    if(sender() == (QObject *)subfom->m_edit2)
        flag = 4;
    syszuxpinyin->lineEdit_window->setText(data);
    syszuxpinyin->resize(800,310);
    syszuxpinyin->move(0,170);
    syszuxpinyin->show();

}

void Widget::confirmString(QString gemfield){
    if(flag == 1)
        m_edit->setText(gemfield);
    if(flag == 2)
        m_edit2->setText(gemfield);
    if(flag == 3)
        subfom->m_edit->setText(gemfield);
    if(flag == 4)
        subfom->m_edit2->setText(gemfield);
}


void Widget::on_pushButton_clicked()
{
    subfom->show();
}
